//
//  QSNavigationController.swift
//  TestSwift
//
//  Created by Song on 2018/4/29.
//  Copyright © 2018年 Song. All rights reserved.
//

import UIKit

class QSNavigationController: UINavigationController {
    // 属性设置
    let titleFont = UIFont.systemFont(ofSize: 20.0)
    let titleColor = UIColor.black
    let largeTitleFont: UIFont? = nil
    let largeTitleColor = UIColor.black

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let navBar = self.navigationBar
        // 去除透明
        navBar.isTranslucent = false
        
        // 设置导航栏title的字体大小和颜色
        navBar.titleTextAttributes = [NSAttributedStringKey.font : titleFont, NSAttributedStringKey.foregroundColor : titleColor]
        // 大标题
        if #available(iOS 11.0, *) {
            // 默认不用大标题
            navBar.prefersLargeTitles = false
            
            if navBar.prefersLargeTitles {
                var attDict = Dictionary<NSAttributedStringKey, Any>.init()
                attDict[NSAttributedStringKey.foregroundColor] = largeTitleColor
                
                if largeTitleFont != nil {
                    attDict[NSAttributedStringKey.font] = largeTitleFont!
                }
                
                navBar.largeTitleTextAttributes = attDict
            }
        }
    }
    
    // MARK: - 重写push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if self.childViewControllers.count > 0 {
            // 隐藏下方工具条
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: animated)
    }
}
